/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.mlbs.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 *
 * @author mckd87
 */
@Entity
@Table(name = "device")
@NamedQueries({@NamedQuery(name = "Device.findByDeviceid", query = "SELECT d FROM Device d WHERE d.deviceid = :deviceid"), @NamedQuery(name = "Device.findByPhoneno", query = "SELECT d FROM Device d WHERE d.phoneno = :phoneno"), @NamedQuery(name = "Device.findByName", query = "SELECT d FROM Device d WHERE d.name = :name")})
public class Device implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Column(name = "deviceid", nullable = false)
    private String deviceid;
    @Column(name = "phoneno")
    private String phoneno;
    @Column(name = "name")
    private String name;
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "device")
    private Devicelocation devicelocation;
    @JoinColumn(name = "typeId", referencedColumnName = "typeId")
    @ManyToOne
    private Devicetype typeId;
    @JoinColumn(name = "userid", referencedColumnName = "userId")
    @ManyToOne
    private Usertable userid;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "deviceId")
    private Collection<Pagecache> pagecacheCollection;
    @OneToMany(mappedBy = "deviceid")
    private Collection<Appusage> appusageCollection;
    @OneToMany(mappedBy = "deviceid", fetch=FetchType.EAGER)
    private Collection<Preferences> preferencesCollection;

    public Device() {
        preferencesCollection = new ArrayList<Preferences>();
        pagecacheCollection = new ArrayList<Pagecache>();
        appusageCollection = new ArrayList<Appusage>();
    }

    public Device(String deviceid) {
        this.deviceid = deviceid;
        preferencesCollection = new ArrayList<Preferences>();
        pagecacheCollection = new ArrayList<Pagecache>();
        appusageCollection = new ArrayList<Appusage>();
    }

    public String getDeviceid() {
        return deviceid;
    }

    public void setDeviceid(String deviceid) {
        this.deviceid = deviceid;
    }

    public String getPhoneno() {
        return phoneno;
    }

    public void setPhoneno(String phoneno) {
        this.phoneno = phoneno;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Devicelocation getDevicelocation() {
        return devicelocation;
    }

    public void setDevicelocation(Devicelocation devicelocation) {
        this.devicelocation = devicelocation;
    }

    public Devicetype getTypeId() {
        return typeId;
    }

    public void setTypeId(Devicetype typeId) {
        this.typeId = typeId;
    }

    public Usertable getUserid() {
        return userid;
    }

    public void setUserid(Usertable userid) {
        this.userid = userid;
    }

    public Collection<Pagecache> getPagecacheCollection() {
        return pagecacheCollection;
    }

    public void setPagecacheCollection(Collection<Pagecache> pagecacheCollection) {
        this.pagecacheCollection = pagecacheCollection;
    }

    public Collection<Appusage> getAppusageCollection() {
        return appusageCollection;
    }

    public void setAppusageCollection(Collection<Appusage> appusageCollection) {
        this.appusageCollection = appusageCollection;
    }

    public Collection<Preferences> getPreferencesCollection() {
        return preferencesCollection;
    }

    public void setPreferencesCollection(Collection<Preferences> preferencesCollection) {
        this.preferencesCollection = preferencesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (deviceid != null ? deviceid.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Device)) {
            return false;
        }
        Device other = (Device) object;
        if ((this.deviceid == null && other.deviceid != null) || (this.deviceid != null && !this.deviceid.equals(other.deviceid))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.mlbs.entity.Device[deviceid=" + deviceid + "]";
    }

}
